package com.feng.common.web;

/**
 * Web Response Builder
 */
public class WebCommonResponseBuilder<T> {

    private WebCommonResponse<T> webCommonResponse;

    public WebCommonResponseBuilder() {
        webCommonResponse = new WebCommonResponse<>();
    }

    public WebCommonResponse<T> build(){
        return this.webCommonResponse;
    }

    public WebCommonResponse<T> build(T responseData){
        webCommonResponse.setResponseData(responseData);
        return this.webCommonResponse;
    }

    public WebCommonResponseBuilder<T> success() {
        this.success(WebCommonResponse.CODE_OK,WebCommonResponse.DESC_SUCCESS);
        return this;
    }

    public WebCommonResponseBuilder<T> success(String code,String desc){
        webCommonResponse.setStatusCode(code);
        webCommonResponse.setStatusDesc(desc);
        return this;
    }

    public WebCommonResponseBuilder<T> fail(){
        this.fail(WebCommonResponse.CODE_UN_KNOW_FAIL,WebCommonResponse.DESC_UN_KNOW_FAIL);
        return this;
    }

    public WebCommonResponseBuilder<T> fail(String code,String desc) {
        webCommonResponse.setStatusCode(code);
        webCommonResponse.setStatusDesc(desc);
        return this;
    }
}
